package com.hutu.erp.catalog.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hutu.erp.catalog.domain.SpecificationOption;
import com.hutu.erp.catalog.service.ISpecificationOptionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品参数Controller
 * 
 * @author ruoyi
 * @date 2021-05-24
 */
@RestController
@RequestMapping("/catalog/specification_option")
public class SpecificationOptionController extends BaseController
{
    @Autowired
    private ISpecificationOptionService specificationOptionService;

    /**
     * 查询商品参数列表
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_option:list')")
    @GetMapping("/list")
    public TableDataInfo list(SpecificationOption specificationOption)
    {
        startPage();
        List<SpecificationOption> list = specificationOptionService.selectSpecificationOptionList(specificationOption);
        return getDataTable(list);
    }

    /**
     * 导出商品参数列表
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_option:export')")
    @Log(title = "商品参数", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SpecificationOption specificationOption)
    {
        List<SpecificationOption> list = specificationOptionService.selectSpecificationOptionList(specificationOption);
        ExcelUtil<SpecificationOption> util = new ExcelUtil<SpecificationOption>(SpecificationOption.class);
        return util.exportExcel(list, "商品参数数据");
    }

    /**
     * 获取商品参数详细信息
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_option:query')")
    @GetMapping(value = "/{optionId}")
    public AjaxResult getInfo(@PathVariable("optionId") Long optionId)
    {
        return AjaxResult.success(specificationOptionService.selectSpecificationOptionById(optionId));
    }

    /**
     * 新增商品参数
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_option:add')")
    @Log(title = "商品参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpecificationOption specificationOption)
    {
        return toAjax(specificationOptionService.insertSpecificationOption(specificationOption));
    }

    /**
     * 修改商品参数
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_option:edit')")
    @Log(title = "商品参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpecificationOption specificationOption)
    {
        return toAjax(specificationOptionService.updateSpecificationOption(specificationOption));
    }

    /**
     * 删除商品参数
     */
    @PreAuthorize("@ss.hasPermi('catalog:specification_option:remove')")
    @Log(title = "商品参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{optionIds}")
    public AjaxResult remove(@PathVariable Long[] optionIds)
    {
        return toAjax(specificationOptionService.deleteSpecificationOptionByIds(optionIds));
    }
}
